<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * 项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['groups']=pdo_getall('jy_shopbaoxiu_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
$return['order_types']=$this->order_types;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	} 
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_shopbaoxiu_list',$params,array($pindex,$psize),$total,$fields,'','paixu desc,id desc');
	if($list){
		foreach($list as &$item){
			
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'项目列表'),
			array('op'=>'edit','title'=>'添加项目'),
		),
		'list'=>array('data'=>'list','tip'=>'[温馨提示]:</br>1、客户保修时，直接选择维修项目！','edit'=>true,'list'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string'),
			array('name'=>'image','title'=>'图片','type'=>'image'),
			array('name'=>'groupid','title'=>'所属分类','type'=>'select','options'=>'groups'),
			array('name'=>'price','title'=>'项目价','type'=>'string'),
			array('name'=>'vip_price','title'=>'VIP价','type'=>'string'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
		)),
		'search'=>array(
			array('name'=>'title','title'=>'项目名称','type'=>'string','width'=>'20'),
			array('name'=>'status','title'=>'是否启用','type'=>'select','options'=>'status','width'=>'20'),
		)
	);
	$return['status']=array(array('id'=>'0','title'=>'禁用'),array('id'=>'1','title'=>'启用'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_shopbaoxiu_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回项目列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
						array(
							'title'=>'基本信息',
							'list'=>array(
								array('name'=>'groupid','title'=>'所属分类','type'=>'select','options'=>'groups'),
								array('name'=>'title','title'=>'项目名称','type'=>'string'),
								array('name'=>'image','title'=>'项目图片','type'=>'image'),
								array('type'=>'unitstring','title'=>'项目价格','name'=>'price','unit'=>'元'),
								array('type'=>'unitstring','title'=>'VIP价格','name'=>'vip_price','unit'=>'元'),
								array('name'=>'order_types','title'=>'服务类型','type'=>'checkbox','options'=>'order_types'),
								array('name'=>'desc','title'=>'项目描述','type'=>'string'),
								array('name'=>'content','title'=>'项目内容','type'=>'richtext'),
								array('name'=>'paixu','title'=>'项目排序','type'=>'string'),
							)
						),
			
			)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['groupid']){
		exi('请选择项目分类','error');
	}
	if($postdata['price']<=0){
		exi('项目价格必填','error');
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'desc'=>trim($postdata['desc']),
		'image'=>trim($postdata['image']),
		'price'=>trim($postdata['price']),
		'vip_price'=>trim($postdata['vip_price']),
		'content'=>trim($postdata['content']),
		'groupid'=>intval($postdata['groupid']),
		'paixu'=>intval($postdata['paixu']),
		'order_types'=>trim($postdata['order_types']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_shopbaoxiu_list',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		if($isadd['id']){
			exi('该项目已经参与了其他拼团活动！','error');
		}
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_shopbaoxiu_list',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_shopbaoxiu_list',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的项目！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_shopbaoxiu_list',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
